package com.gxa.modules.app.outpatient.waitcure.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxa.common.utils.Result;
import com.gxa.modules.app.hospitalization.persional.service.PatientService;
import com.gxa.modules.model.entity.book.BookRegister;
import com.gxa.modules.model.entity.fee.Patient;
import com.gxa.modules.model.vo.WaitVO;
import com.gxa.modules.pc.hospital.service.DepartmentService;
import com.gxa.modules.pc.order.service.BookRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/11/19 12:24
 **/
@RestController
@Api(tags = "APP端--门诊服务--候诊查询")
public class WatiCureController {
    @Autowired
    private PatientService patientService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private BookRegisterService bookRegisterService;

    @ApiOperation("根据用户id获取用户信息")
    @GetMapping("/getUserInfo/{userId}")
    public Result getUserInfo(@ApiParam(value = "当前登录用户的id") @PathVariable("userId") Integer userId){
        List<Patient> query = patientService.query(userId);
        return new Result().ok(query);
    }
    @ApiOperation("根据用户id查看是否预约 预约了就能看到预约单号 ，下一个接口使用")
    @GetMapping("/appoint/{userId}")
    public Result getAppointInfo(@ApiParam(value = "当前登录用户的id") @PathVariable("userId") Integer userId){
        List<BookRegister> bookRegisters = bookRegisterService.getBaseMapper().selectList(new QueryWrapper<BookRegister>().eq(!StringUtils.isBlank(Integer.toString(userId)), "user_id", userId));
        if(bookRegisters == null){
            return new Result().ok("该用户没有预约");
        }
        List<Long> appointIds = new ArrayList<>();
        for (BookRegister bookRegister:bookRegisters){
            appointIds.add(bookRegister.getRegisterId());
        }
        return new Result().ok(appointIds);
    }

    @ApiOperation("查询")
    @GetMapping("/app/wait/{userId}")
    public Result getAppGigNames(@ApiParam(value = "当前登录用户的id",required = true) @PathVariable("userId") Integer userId){
       List<WaitVO> wait = departmentService.getWaitFromDoctor(userId);
        return new Result().ok(wait);
    }
    @ApiOperation("更新")
    @GetMapping("/app/update")
    public Result updateRandomSort(@RequestParam("appointId") Integer appointId){
        int  num = departmentService.randomUpdate(appointId);
        return new Result().ok(num);
    }
}
